package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MesClientMapper;
import com.ruoyi.system.domain.MesClient;
import com.ruoyi.system.service.IMesClientService;

/**
 * 客户Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-01
 */
@Service
public class MesClientServiceImpl implements IMesClientService 
{
    @Autowired
    private MesClientMapper mesClientMapper;

    /**
     * 查询客户
     * 
     * @param id 客户主键
     * @return 客户
     */
    @Override
    public MesClient selectMesClientById(Integer id)
    {
        return mesClientMapper.selectMesClientById(id);
    }

    /**
     * 查询客户列表
     * 
     * @param mesClient 客户
     * @return 客户
     */
    @Override
    public List<MesClient> selectMesClientList(MesClient mesClient)
    {
        return mesClientMapper.selectMesClientList(mesClient);
    }

    /**
     * 新增客户
     * 
     * @param mesClient 客户
     * @return 结果
     */
    @Override
    public int insertMesClient(MesClient mesClient)
    {
        return mesClientMapper.insertMesClient(mesClient);
    }

    /**
     * 修改客户
     * 
     * @param mesClient 客户
     * @return 结果
     */
    @Override
    public int updateMesClient(MesClient mesClient)
    {
        return mesClientMapper.updateMesClient(mesClient);
    }

    /**
     * 批量删除客户
     * 
     * @param ids 需要删除的客户主键
     * @return 结果
     */
    @Override
    public int deleteMesClientByIds(Integer[] ids)
    {
        return mesClientMapper.deleteMesClientByIds(ids);
    }

    /**
     * 删除客户信息
     * 
     * @param id 客户主键
     * @return 结果
     */
    @Override
    public int deleteMesClientById(Integer id)
    {
        return mesClientMapper.deleteMesClientById(id);
    }

    @Override
    public boolean isClientIdUnique(MesClient mesClient, Boolean addOrUpdate)
    {
        int count = mesClientMapper.countByClientId(mesClient.getClientId());
        if(addOrUpdate) {
            return count == 0;
        }
        else {
            if(mesClient.getClientId().equals(mesClient.getOldClientId())){
                return count == 1;
            }
            else {
                return count == 0;
            }
        }
    }
}
